`<template>
  <el-card>
    <!-- 查询条件开始 -->
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="路径" prop="path">
        <el-input
            v-model="queryParams.data.path"
            placeholder="请输入路径"
            clearable
            size="small"
            style="width:200px"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="creatBy">
        <el-input
            v-model="queryParams.data.creatBy"
            placeholder="请输入创建者名称"
            clearable
            size="small"
            style="width:200px"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select
            v-model="queryParams.data.type"
            placeholder="请选择类型"
            clearable
            size="small"
            style="width:200px"
        >
          <el-option
              v-for="dict in TypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
            v-model="queryParams.data.status"
            placeholder="请选择类型"
            clearable
            size="small"
            style="width:200px"
        >
          <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
            v-model="queryParams.data.dateRange"
            size="small"
            style="width:240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholde="开始日期"
            end-placeholde="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询条件结束 -->
    <!-- 表头按钮开始 -->
    <el-row :gutter="10" style="margin-bottom: 8px;">
      <el-col :span="1.5">
        <el-button type="success" icon="el-icon-thumb" size="mini" @click="add">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">
          批量删除
        </el-button>
      </el-col>
    </el-row>
    <!-- 表头按钮结束 -->
    <!-- 数据表格开始 -->
    <el-table v-loading="loading" border :data="infoTableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="类型" align="center" prop="typeName"/>
      <el-table-column label="路径" align="center" prop="path"/>
      <el-table-column label="状态" prop="statusName" align="center"/>
      <el-table-column label="创建者" align="center" prop="creatBy" width="200"/>
      <el-table-column label="创建时间" align="center" prop="creatTime" width="200"/>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">

<!--          <el-button type="text" icon="el-icon-edit" size="mini"-->
<!--                     @click="update(scope.row)">修改-->
<!--          </el-button>-->
          <el-button type="text" icon="el-icon-delete" size="mini"
                     @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 数据表格结束 -->

    <!-- 分页控件开始 -->
    <el-pagination
        v-show="total>0"
        :current-page="queryParams.pageNo"
        :page-sizes="[5,10,20,30]"
        :page-size="queryParams.pageSize"
        layout="total,sizes,prev,pager,next,jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
    <!-- 分页控件结束 -->

    <!--  新增对话框 -->
    <el-dialog title="新增 白名单" :visible="newAddDialog" width="500px" center append-to-body @close="cancel">
      <el-form label-width="80px" ref="newParams" :rules="rules" :model="newParams">
        <el-form-item label="路径" prop="path">
          <el-input v-model="newParams.path" placeholder="请输入路径" clearable size="small" style="width: 300px"/>
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="newParams.type" placeholder="请选择类型" clearable size="small" style="width: 300px">
            <el-option v-for="dict in TypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"/>
          </el-select>
        </el-form-item>
        <el-form-item label="状态"  prop="status">
          <el-select v-model="newParams.status" placeholder="请选择类型" clearable size="small" style="width: 300px">
            <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"/>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="newParams.remark" placeholder="请输入备注" clearable size="small" style="width: 300px"/>
        </el-form-item>
        <el-form-item style="margin-left: 90px">
          <el-button type="primary" size="mini" @click="insertWhite('newParams')">保存</el-button>
          <el-button size="mini" @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </el-card>
</template>

<script>

export default {
  // 声明数据
  data() {
    return {
      // 新增对话框
      newAddDialog: false,
      // 遮罩层
      loading: false,
      // 选中多条
      multiple: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      // 用户数据数据
      infoTableList: [],
      // 状态数据字典
      statusOptions: [],
      // 类型数据字典
      TypeOptions: [],
      // // 时间
      // dateRange: [],
      // 添加参数
      newParams:{

      },


      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 5,
        data:{},
      },

      rules: {
        path: [
          { required: true, message: '请输入路径', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择类型', trigger: 'change' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'change' }
        ]
      }
    }
  },
  // 初始化
  created() {
    // 查询条件的状态
    this.$http.get('/whiteName/getStatus').then(res => {
      this.statusOptions = res.data.data
      console.log(this.statusOptions)
    })
    // 查询条件的操作类型
    this.$http.get('/whiteName/getType').then(res => {
      this.TypeOptions = res.data.data
      console.log(this.TypeOptions)
    })
    // 做查询
    this.getloginInfoList()
  },
  // 自定义方法
  methods: {
    // 查询所有数据列表
    getloginInfoList() {
      console.log(this.queryParams)
      this.loading = true
      this.$http.post("/whiteName/queryByPage",this.queryParams).then(res => {
        this.infoTableList = res.data.data.list
        this.total = res.data.data.total
        this.loading = false
      })
    },
    // 新增
    add(){
      this.newParams = {}
      this.newAddDialog = true
    },
    cancel(){
      this.newParams = {}
      this.newAddDialog = false
      this.$refs['newParams'].resetFields(); // 清除表单验证状态
    },
    // 新增白名单
    insertWhite(formName){
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 提交表单
          this.$http.post("/whiteName/insertWhite",this.newParams).then(res => {
            if (res.data.code === 200){
              this.$message.success('新增成功')
              this.$refs[formName].resetFields()
              this.getloginInfoList()// 全查询
            } else {
              this.$message.error(res.data.msg)
            }
          })
          this.newAddDialog = false
        }
      });
    },


    // 条件查询
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getloginInfoList()
    },
    // 重置查询条件
    resetQuery() {
      this.queryParams={
        pageNo: 1,
        pageSize: 5,
        data:{},
      }
      this.getloginInfoList()
    },
    // 数据表格的多选择框选择时触发
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },
    // 分页pageSize变化时触发
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      // 重新查询
      this.getloginInfoList()
    },
    // 点击上一页  下一页，跳转到哪一页面时触发
    handleCurrentChange(val) {
      this.queryParams.pageNo = val
      // 重新查询
      this.getloginInfoList()
    },
    // 翻译登陆状态
    statusFormatter(row) {
      let statusLabel = "未知";
      this.statusOptions.filter(item => {
        if (item.dictValue === row.status) {
          statusLabel = item.dictLabel
        }
      })
      return  statusLabel
    },
    // 翻译登陆类型
    typeFormatter(row) {
      let statusLabel = "未知";
      this.TypeOptions.filter(item => {
        if (item.dictValue === row.type) {
          statusLabel = item.dictLabel
        }
      })
      return statusLabel
    },
    // 删除或者批量删除
    handleDelete(row) {
      const infoIds = row.id || this.ids
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        console.log(infoIds)
        this.$http.delete("/whiteName/deleteByIds/"+infoIds).then(res => {
          this.loading = false
          this.$message.success('删除成功')
          this.getloginInfoList()
        })
      }).catch(() => {
        this.$message.error('删除已取消')
        this.loading = false
      })
    },
  }
}
</script>

<style scoped>

</style>`